package com.zhaungwei.weather.controller;

import com.zhaungwei.weather.service.CityDataService;
import com.zhaungwei.weather.service.WeatherReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * Weather Report Controller.
 *
 * @author LeviCoder
 * @create 2019-03-24 12:45
 */
@Controller
@RequestMapping("/report")
public class WeatherReportController {

    @Autowired
    private CityDataService cityDataService;

    @Autowired
    private WeatherReportService weatherReportService;

    @GetMapping("/citykey/{citykey}")
    public ModelAndView getReportByCityId(@PathVariable("citykey") String citykey, Model model) throws Exception {
        model.addAttribute("title", "文希的天气预报");
        model.addAttribute("citykey", citykey);
        model.addAttribute("cityList", cityDataService.listCity());
        model.addAttribute("report", weatherReportService.getDataByCitykey(citykey));
        return new ModelAndView("weather/report", "reportModel", model);
    }
}
